package cn.context;

import cn.WorkType;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class StrategyWorkType {
    private Map<String, List<WorkType>> workTypeMap;

    public StrategyWorkType() {
        this.workTypeMap = new HashMap<>(10);
    }

    /****
     *   月份作为 key , value 是每月人数
     *
     * */
    public void setWorkType(String mouth, WorkType workType) {
        if (this.workTypeMap.containsKey(mouth)) {
            this.workTypeMap.get(mouth).add(workType);
        } else {
            List<WorkType> workTypes = new ArrayList<>();
            workTypes.add(workType);
            this.workTypeMap.put(mouth, workTypes);
        }
    }

    public void total() {

        for (String key : this.workTypeMap.keySet()) {
            BigDecimal total = new BigDecimal("0");
            List<WorkType> workTypes = this.workTypeMap.get(key);
            for (WorkType workType : workTypes) {
                total = total.add(workType.calc());
            }
            //四舍五入保留2位
            System.out.println(key + " 月份,应发工资：" + total.setScale(2, BigDecimal.ROUND_HALF_UP).toString());
            total = null;
        }
    }
}
